﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore;
using OABackground.Entities;

namespace OABackground.Infrastructure
{
    public class MaterialapplySubmitRepository
    {
        #region 物资申请增删改查
        public void Add(Materialapply Material)//添加一个物资申请
        {

            using (var dbContext = new oaContext())
            {

                dbContext.Add(Material);//这不是真的添加
                dbContext.SaveChanges();//用“保存”表示一次事务的完成
            }
        }
        public void Update(Materialapply Material)//更新物资申请
        {
            using (var dbContext = new oaContext())
            {
                dbContext.Update(Material);
                dbContext.SaveChanges();
            }
        }
        public Materialapply Query(int Id)//查找物资申请
        {

            using (var dbContext = new oaContext())
            {
                var select = dbContext.Materialapply.Find(Id);
                dbContext.SaveChanges();

                return select;
            }
        }
        public List<Materialapply> QueryByTeacher(string Tid)//根据教师id查找物资
        {
            List<Materialapply> materiallist = new List<Materialapply>();

            using (var dbcontext = new oaContext())
            {
                materiallist = dbcontext.Materialapply.
                    FromSql($"select * from Materialapply where Tid={Tid}").ToList();
                dbcontext.SaveChanges();

                return materiallist;
            }
        }
        public void Delete(int Id)//删除物资申请
        {
            using (var dbContext = new oaContext())
            {
                var select = dbContext.Teacherinfomation.Find(Id);
                dbContext.Remove(select);
                dbContext.SaveChanges();
            }

        }
        #endregion
    }
}
